package com.tenghui.common.enums;

/**
 * 订单状态枚举
 */
public enum OrderStatus {
    CANCELED("0", "已取消"),
    WAITING_PAY("1", "待付款"),
    WAITING_SHIP("2", "待发货"),
    WAITING_RECEIVE("3", "待收货"),
    COMPLETED("10", "已完成");

    private final String code;  // 字典键值
    private final String description;  // 字典标签

    OrderStatus(String code, String description) {
        this.code = code;
        this.description = description;
    }

    /**
     * 根据描述获取枚举
     */
    public static OrderStatus getByDescription(String desc) {
        for (OrderStatus status : values()) {
            if (status.description.equals(desc)) {
                return status;
            }
        }
        return CANCELED; // 默认返回已取消
    }

    /**
     * 根据code获取枚举
     */
    public static OrderStatus getByCode(String code) {
        for (OrderStatus status : values()) {
            if (status.code.equals(code)) {
                return status;
            }
        }
        return CANCELED; // 默认返回已取消
    }
}